package view;

import controller.SelfUserDetailsListener;
import pojo.User;

import javax.swing.*;
import java.awt.*;

public class SelfUserDetails extends JDialog {
    private JLabel labelId, labelPW, labelName, labelGender, labelPN, labelType;
    //文本框
    private JTextField tfNum, tfPN, tfName, tfGender, tfType;
    //密码
    private JPasswordField tfPwd;
    private JButton jButton1,jButton2,jButton3;
    private User user;
    private SelfUserDetailsListener selfUserDetailsListener;
    private SelfUserView selfUserView;
    public SelfUserDetails(User user,SelfUserView selfUserView){
        this.user=user;
        this.selfUserView=selfUserView;
        selfUserDetailsListener=new SelfUserDetailsListener(this,selfUserView);
        this.setTitle("用户信息");
        this.setSize(400, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
        this.add(this.getPanel(),BorderLayout.CENTER);
        this.add(this.getButton(),BorderLayout.SOUTH);
    }
    public JPanel getPanel(){
        JPanel jPanel=new JPanel();

        jPanel.setLayout(new GridLayout(5, 2));
        labelId = new JLabel("                           学号:");
        labelName = new JLabel("                           姓名:");
        labelGender = new JLabel("                           年级:");
        labelPN = new JLabel("                           电话:");
        labelType = new JLabel("                           类别");
        tfNum = new JTextField(user.getUserId(),15);
        tfName = new JTextField(user.getUserName(),15);
        tfGender = new JTextField(user.getGender(),15);
        tfPN = new JTextField(user.getPhoneNumber(),15);
        tfType = new JTextField(user.getType(),15);
        tfNum.setEditable(false);
        tfType.setEditable(false);
        jPanel.add(labelId);
        jPanel.add(tfNum);

        jPanel.add(labelName);
        jPanel.add(tfName);

        jPanel.add(labelGender);
        jPanel.add(tfGender);

        jPanel.add(labelPN);
        jPanel.add(tfPN);

        jPanel.add(labelType);
        jPanel.add(tfType);

        return jPanel;
    }
    public JPanel getButton(){
        JPanel jPanel=new JPanel();
        jButton1=new JButton("修改");
        jButton3=new JButton("返回");
        jPanel.add(jButton1);

        jPanel.add(jButton3);
        jButton1.addActionListener(selfUserDetailsListener);

        jButton3.addActionListener(selfUserDetailsListener);
        return jPanel;
    }

    public JLabel getLabelId() {
        return labelId;
    }

    public JTextField getTfNum() {
        return tfNum;
    }

    public JTextField getTfPN() {
        return tfPN;
    }

    public JTextField getTfName() {
        return tfName;
    }

    public JTextField getTfGender() {
        return tfGender;
    }

    public JTextField getTfType() {
        return tfType;
    }

    public JPasswordField getTfPwd() {
        return tfPwd;
    }

    public User getUser() {
        return user;
    }
}
